package com.zoro.jianyue.utils;

import android.net.Uri;
import android.util.StringBuilderPrinter;

import com.zoro.jianyue.api.ApiConstants;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * Created by CM-ZR on 2016/1/29.
 */
public class UriHelper {
    private static volatile UriHelper instance = null;
    /**
     * 20 datas per page
     */
    public static final int PAGE_LIMIT = 20;

    private UriHelper() {

    }

    public static UriHelper getInstance() {
        if (null == instance) {
            synchronized (UriHelper.class) {
                instance = new UriHelper();
            }
        }
        return instance;
    }

    public String getImageListUrl(String keywords, int pageNum) {
        StringBuffer sb = new StringBuffer();
        sb.append(ApiConstants.Urls.BAIDU_IMAGES_URLS);
        sb.append("?col=");
        try {
            sb.append(URLEncoder.encode(keywords,"UTF-8"));
            sb.append("&tag=");
            sb.append(URLEncoder.encode("全部","UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        sb.append("&pn=");
        sb.append(pageNum * PAGE_LIMIT);
        sb.append("&rn=");
        sb.append(PAGE_LIMIT);
        sb.append("&from=1");
        return sb.toString();
    }
}
